<?php
$menumark = 'house';
switch ($act) {
    //#####################@ 修改分类 @#####################//
    case 'edit':
        if (isGet()) {

            $house_server = $db->pe_selectall('server');
            $house = $db->pe_select('house', array('house_id' => $_g_id));
            $house['house_server'] = explode('|', $house['house_server']);
//            mp($house);exit;
            include(pe_tpl('house_edit.html'));
        } else if (isPost()) {
            $_p_info['house_server'] = implode('|', $_p_server);
            if ($_FILES['house_img']['size']) {
                pe_lead('include/class/upload.class.php');
                $upload = new upload($_FILES['house_img']);
                $_p_info['house_img'] = $upload->filehost;
            }

            $result = $db->pe_update("house", array('house_id' => $_g_id), $_p_info);
            if ($result) {
                pe_success('修改成功', 'admin.php?mod=house');
            } else {
                pe_error('修改失败');
            }

        }

        break;

    case 'del':
        pe_token_match();
        $result = $db->pe_delete('house', array('house_id' => $_g_id));

        //同时删除wxgg_fj里的相同房型，wxgg_houseimg里的相同房型,该房型的红包也一并删除
        $db->pe_delete('fj',array('fj_houseid'=>$_g_id));
        $db->pe_delete('houseimg',array('houseimg_houseid'=>$_g_id));
        $db->pe_delete('redpack',array('redpack_houseid'=>$_g_id));
        //怎么删
        if ($result) {
            pe_success('删除成功!');
        } else {
            pe_error('删除失败...');
        }
        include(pe_tpl('house_list.html'));
        break;

    case 'add':

        if (isGet()) {

            $house_server = $db->pe_selectall('server');
            include(pe_tpl('house_add.html'));
        } else if (isPost()) {
            $_p_info['house_server'] = "";
            $_p_info['house_server'] = implode('|', $_p_server);
            if ($_FILES['house_img']['size']) {
                pe_lead('include/class/upload.class.php');
                $upload = new upload($_FILES['house_img']);
                $_p_info['house_img'] = $upload->filehost;
            }

            $result = $db->pe_insert("house", $_p_info);

            if ($result) {
                pe_success('添加成功', 'admin.php?mod=house&act=add');
            } else {
                pe_error('添加失败');
            }

        }

        break;
    //下架
    case 'cool':
        if($db->pe_update('house',array('house_id'=>$_g_id),array('house_state'=>1))){
            pe_success('下架成功','admin.php?mod=house');
        }else{
            pe_error('下架失败','admin.php?mod=house');
        }
        include(pe_tpl('house_list.html'));
        break;
    //上架

    case 'recover':
        if($db->pe_update('house',array('house_id'=>$_g_id),array('house_state'=>0))){
            pe_success('上架成功','admin.php?mod=house');
        }else{
            pe_error('上架失败','admin.php?mod=house');
        }
        include(pe_tpl('house_list.html'));
        break;

    //#####################@ 分类列表 @#####################//
    default :
         ob_clean();
        $house = $db->pe_selectall('house');

        foreach ($house as $k => $v) {
            $server_name = [];
            $server_id = explode('|', $v['house_server']);

            foreach ($server_id as $id) {
                $server = $db->pe_select('server', array('server_id' => $id), 'server_name');
                $server_name[] = $server['server_name'];
            }

            $house[$k]['server'] = $server_name;

        }

        include(pe_tpl('house_list.html'));

        break;
}
?>